package com.bdqn.tour.service.impl;

import com.bdqn.tour.dao.GyhLoginDao;
import com.bdqn.tour.dao.impl.GyhLoginDaoImpl;
import com.bdqn.tour.pojo.User;
import com.bdqn.tour.service.GyhLoginservice;
import com.bdqn.tour.util.MD5Util;

import java.util.HashMap;
import java.util.Map;

public class GyhLoginserviceImpl implements GyhLoginservice {
    //调用dao层
    GyhLoginDao dao=new GyhLoginDaoImpl();

    @Override
    public Map<String, Object> getLogin(String phone, String password) {
        //1.返回对象
        Map<String, Object> map = new HashMap<>();
        //2.调用接口 查询员工信息
        User user = dao.getLogin(phone);
        String code = "0000";
        String msg = "登录成功";
        if(user == null){
            code = "1001";
            msg = "用户名不存在";
        }else{
            //密码比较  [数据库存储的是加密的， 故此处比较时也需要加密]
            password = MD5Util.md5(password,5);
            if(!password.equals(user.getPassword())){
                code = "1002";
                msg = "密码错误";
            }
        }
        map.put("code",code);
        map.put("msg",msg);
        map.put("user",user);
        return map;
    }

    @Override
    public User getLoginCheck(String phone) {
        return dao.getLoginCheck(phone);
    }
}
